/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Preferencias.java
 *
 * Created on 22/06/2011, 22:24:40
 */
package br.com.nextsql;

import br.com.nextsql.renderizar.*;
import java.awt.*;
import java.io.*;
import java.util.Properties;
import javax.swing.*;

public class Preferencias extends javax.swing.JDialog {
    private boolean retorno = false;
    private Properties principal;
    private String linguaArquivos[];
    private String fontesEncontradas[];
    private Properties lingua;
    public boolean isRetorno() {
        return retorno;
    }
    /** Creates new form Preferencias */
    
    public Preferencias(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        traducao();
        listarLinguas();
    }
    private void traducao(){
        lingua = GlobalConf.lerLingua();
        setTitle(lingua.getProperty("preferencias"));
        btSalvar.setText(lingua.getProperty("salvar"));
        btCancelar.setText(lingua.getProperty("cancelar"));
        cbItalico.setText(lingua.getProperty("italico"));
        cbNegrito.setText(lingua.getProperty("negrito"));
        cbSublinhado.setText(lingua.getProperty("sublinhado"));
        pnExemplo.setBorder(javax.swing.BorderFactory.createTitledBorder(lingua.getProperty("exemplo")+":"));
        pnFonte.setBorder(javax.swing.BorderFactory.createTitledBorder(lingua.getProperty("fonte")+":"));
        pnTabulacao.setBorder(javax.swing.BorderFactory.createTitledBorder(lingua.getProperty("tabulacao")+":"));
        tabs.setTitleAt(0, lingua.getProperty("geral"));//Geral
        tabs.setTitleAt(1, lingua.getProperty("fonteCores"));//Geral
        txtBancoDados.setText(lingua.getProperty("bancoDados"));
        txtCorRealce.setText(lingua.getProperty("corRealce"));
        txtCorTexto.setText(lingua.getProperty("corTexto"));
        txtElementos.setText(lingua.getProperty("elementos")+":");
        txtLingua.setText(lingua.getProperty("lingua")+":");
        //Definição de estilos
        tpExemplo.setBorder(new BordaNumerada());
        //tpExemplo.setDocument(new AcharPalavras());
        tpExemplo.setText(lingua.getProperty("Texto.Modelo"));
    }
    private void listarLinguas(){
        principal = GlobalConf.lerPropriedades();
        /* COMBO DE LINGUAS */
        DefaultComboBoxModel modelLingua = new DefaultComboBoxModel();
        cbLingua.setModel(modelLingua);
        File dir = new File(principal.getProperty("file.linguaDir"));
        FilenameFilter fileType = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(".lingua");
            }
        };
        String[] dirFilhos = dir.list(fileType);
        if(dirFilhos != null){
            for(int i=0; i<dirFilhos.length; i++){
                Properties prop = new Properties();
                try{
                    FileInputStream fis = new FileInputStream(principal.getProperty("file.linguaDir")+dirFilhos[i]);
                    prop.load(fis);
                    cbLingua.addItem(java.util.Arrays.toString(dirFilhos[i].split("\\.lingua"))+" - "+prop.getProperty("Lingua.Definicao"));
                    if(principal.getProperty("file.lingua").equals(dirFilhos[i])){
                        cbLingua.setSelectedIndex(i);
                    }
                    
                }catch(Exception ex){}
            }
            linguaArquivos = dirFilhos;
        }
        /* FIM COMBO DE LINGUAS */
        /* COMBO DE FONTES */
        String[] fontesNomes = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
        DefaultComboBoxModel modelFonte = new DefaultComboBoxModel();
        cbFonte.setModel(modelFonte);
        for(int i=0; i < fontesNomes.length; i++){
            try{
                cbFonte.addItem(fontesNomes[i]);
                if(principal.getProperty("fonte").equals(fontesNomes[i])){
                    cbFonte.setSelectedIndex(i);
                }
            }catch(Exception ex){}
        }
        fontesEncontradas = fontesNomes;
        /* FIM COMBO DE FONTES */
        tfTamanho.setEditor(new JSpinner.NumberEditor (tfTamanho, "###0"));
        tfTamanho.setValue(Integer.parseInt(principal.getProperty("fonte.tamanho")));
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabs = new javax.swing.JTabbedPane();
        pnGeral = new javax.swing.JPanel();
        cbLingua = new javax.swing.JComboBox();
        txtLingua = new javax.swing.JLabel();
        pnFonteCores = new javax.swing.JPanel();
        pnExemplo = new javax.swing.JPanel();
        txtElementos = new javax.swing.JLabel();
        txtCorTexto = new javax.swing.JLabel();
        txtCorRealce = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tpExemplo = new javax.swing.JTextPane();
        jComboBox1 = new javax.swing.JComboBox();
        cbItalico = new javax.swing.JCheckBox();
        cbNegrito = new javax.swing.JCheckBox();
        cbSublinhado = new javax.swing.JCheckBox();
        pnCorRealce = new javax.swing.JPanel();
        pnCorTexto = new javax.swing.JPanel();
        txtBancoDados = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        pnFonte = new javax.swing.JPanel();
        cbFonte = new javax.swing.JComboBox();
        tfTamanho = new javax.swing.JSpinner();
        pnTabulacao = new javax.swing.JPanel();
        jSpinner1 = new javax.swing.JSpinner();
        jToolBar1 = new javax.swing.JToolBar();
        btSalvar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Preferências");

        txtLingua.setText("Lingua:");

        javax.swing.GroupLayout pnGeralLayout = new javax.swing.GroupLayout(pnGeral);
        pnGeral.setLayout(pnGeralLayout);
        pnGeralLayout.setHorizontalGroup(
            pnGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnGeralLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txtLingua)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbLingua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(356, Short.MAX_VALUE))
        );
        pnGeralLayout.setVerticalGroup(
            pnGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnGeralLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnGeralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtLingua)
                    .addComponent(cbLingua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(291, Short.MAX_VALUE))
        );

        tabs.addTab("Geral", new javax.swing.ImageIcon(getClass().getResource("/br/com/nextsql/resources/icons/preferences.png")), pnGeral); // NOI18N

        pnExemplo.setBorder(javax.swing.BorderFactory.createTitledBorder("Exemplo"));

        txtElementos.setText("Elemento:");

        txtCorTexto.setText("Cor do texto");
        txtCorTexto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtCorTextoMouseClicked(evt);
            }
        });

        txtCorRealce.setText("Cor do realce");
        txtCorRealce.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtCorRealceMouseClicked(evt);
            }
        });

        tpExemplo.setEditable(false);
        jScrollPane1.setViewportView(tpExemplo);

        cbItalico.setText("Itálico");

        cbNegrito.setText("Negrito");

        cbSublinhado.setText("Sublinhado");

        pnCorRealce.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnCorRealce.setPreferredSize(new java.awt.Dimension(15, 15));
        pnCorRealce.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnCorRealceMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout pnCorRealceLayout = new javax.swing.GroupLayout(pnCorRealce);
        pnCorRealce.setLayout(pnCorRealceLayout);
        pnCorRealceLayout.setHorizontalGroup(
            pnCorRealceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 13, Short.MAX_VALUE)
        );
        pnCorRealceLayout.setVerticalGroup(
            pnCorRealceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 13, Short.MAX_VALUE)
        );

        pnCorTexto.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnCorTexto.setPreferredSize(new java.awt.Dimension(15, 15));
        pnCorTexto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pnCorTextoMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout pnCorTextoLayout = new javax.swing.GroupLayout(pnCorTexto);
        pnCorTexto.setLayout(pnCorTextoLayout);
        pnCorTextoLayout.setHorizontalGroup(
            pnCorTextoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 13, Short.MAX_VALUE)
        );
        pnCorTextoLayout.setVerticalGroup(
            pnCorTextoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 13, Short.MAX_VALUE)
        );

        txtBancoDados.setText("Banco de dados:");

        javax.swing.GroupLayout pnExemploLayout = new javax.swing.GroupLayout(pnExemplo);
        pnExemplo.setLayout(pnExemploLayout);
        pnExemploLayout.setHorizontalGroup(
            pnExemploLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 427, Short.MAX_VALUE)
            .addGroup(pnExemploLayout.createSequentialGroup()
                .addGroup(pnExemploLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnExemploLayout.createSequentialGroup()
                        .addGap(4, 4, 4)
                        .addComponent(txtElementos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtBancoDados)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnExemploLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cbNegrito)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbItalico)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbSublinhado)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnCorTexto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCorTexto)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pnCorRealce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCorRealce)))
                .addContainerGap())
        );
        pnExemploLayout.setVerticalGroup(
            pnExemploLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnExemploLayout.createSequentialGroup()
                .addGroup(pnExemploLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtElementos)
                    .addComponent(jComboBox1)
                    .addComponent(txtBancoDados)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnExemploLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(cbSublinhado)
                    .addComponent(cbItalico)
                    .addComponent(cbNegrito)
                    .addComponent(pnCorTexto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCorTexto)
                    .addComponent(pnCorRealce, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCorRealce))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))
        );

        pnFonte.setBorder(javax.swing.BorderFactory.createTitledBorder("Fonte"));

        javax.swing.GroupLayout pnFonteLayout = new javax.swing.GroupLayout(pnFonte);
        pnFonte.setLayout(pnFonteLayout);
        pnFonteLayout.setHorizontalGroup(
            pnFonteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnFonteLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbFonte, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tfTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnFonteLayout.setVerticalGroup(
            pnFonteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFonteLayout.createSequentialGroup()
                .addGroup(pnFonteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbFonte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfTamanho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnTabulacao.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabulação"));

        javax.swing.GroupLayout pnTabulacaoLayout = new javax.swing.GroupLayout(pnTabulacao);
        pnTabulacao.setLayout(pnTabulacaoLayout);
        pnTabulacaoLayout.setHorizontalGroup(
            pnTabulacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnTabulacaoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSpinner1, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnTabulacaoLayout.setVerticalGroup(
            pnTabulacaoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnTabulacaoLayout.createSequentialGroup()
                .addComponent(jSpinner1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout pnFonteCoresLayout = new javax.swing.GroupLayout(pnFonteCores);
        pnFonteCores.setLayout(pnFonteCoresLayout);
        pnFonteCoresLayout.setHorizontalGroup(
            pnFonteCoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnExemplo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pnFonteCoresLayout.createSequentialGroup()
                .addComponent(pnFonte, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnTabulacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        pnFonteCoresLayout.setVerticalGroup(
            pnFonteCoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnFonteCoresLayout.createSequentialGroup()
                .addGroup(pnFonteCoresLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnFonte, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnTabulacao, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnExemplo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tabs.addTab("Dados", new javax.swing.ImageIcon(getClass().getResource("/br/com/nextsql/resources/icons/page_white_text.png")), pnFonteCores); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/nextsql/resources/icons/disk.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.setAlignmentX(10.0F);
        btSalvar.setFocusable(false);
        btSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                salvar(evt);
            }
        });
        jToolBar1.add(btSalvar);

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/nextsql/resources/icons/cancel.png"))); // NOI18N
        btCancelar.setText("Cancelar");
        btCancelar.setFocusable(false);
        btCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sair(evt);
            }
        });
        jToolBar1.add(btCancelar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(tabs)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(tabs)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        tabs.getAccessibleContext().setAccessibleName("Geral");

        pack();
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension dialogSize = getSize();
        setLocation((screenSize.width-dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
    }// </editor-fold>//GEN-END:initComponents

    private void sair(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sair
        setVisible(false);
        this.retorno = false;
    }//GEN-LAST:event_sair

    private void salvar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_salvar
        principal.setProperty("file.lingua", linguaArquivos[cbLingua.getSelectedIndex()]);
        principal.setProperty("fonte", fontesEncontradas[cbFonte.getSelectedIndex()]);
        principal.setProperty("fonte.tabulacao", String.valueOf(jSpinner1.getValue()));
        principal.setProperty("fonte.tamanho", String.valueOf(tfTamanho.getValue()));
        try{
            new OrdenadorProperties().OrdenarProperties(principal, GlobalConf.getPrincipalDir()+GlobalConf.getPrincipalFile(), "Arquivo de configuração:");
        }catch(Exception ex){
            JOptionPane.showMessageDialog(null, ex);
        }
        setVisible(false);
        this.retorno = true;
    }//GEN-LAST:event_salvar

    private void pnCorRealceMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnCorRealceMouseClicked
        this.definirCor(pnCorRealce);
    }//GEN-LAST:event_pnCorRealceMouseClicked

    private void txtCorTextoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtCorTextoMouseClicked
        this.definirCor(pnCorTexto);
    }//GEN-LAST:event_txtCorTextoMouseClicked

    private void pnCorTextoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnCorTextoMouseClicked
        this.definirCor(pnCorTexto);
    }//GEN-LAST:event_pnCorTextoMouseClicked

    private void txtCorRealceMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtCorRealceMouseClicked
        this.definirCor(pnCorRealce);
    }//GEN-LAST:event_txtCorRealceMouseClicked
    private void definirCor(JPanel panel){
        Color newColor = JColorChooser.showDialog(null, "Selecione uma cor", panel.getBackground());
        if (newColor != null) {
            panel.setBackground(newColor);
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Preferencias dialog = new Preferencias(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbFonte;
    private javax.swing.JCheckBox cbItalico;
    private javax.swing.JComboBox cbLingua;
    private javax.swing.JCheckBox cbNegrito;
    private javax.swing.JCheckBox cbSublinhado;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JPanel pnCorRealce;
    private javax.swing.JPanel pnCorTexto;
    private javax.swing.JPanel pnExemplo;
    private javax.swing.JPanel pnFonte;
    private javax.swing.JPanel pnFonteCores;
    private javax.swing.JPanel pnGeral;
    private javax.swing.JPanel pnTabulacao;
    private javax.swing.JTabbedPane tabs;
    private javax.swing.JSpinner tfTamanho;
    private javax.swing.JTextPane tpExemplo;
    private javax.swing.JLabel txtBancoDados;
    private javax.swing.JLabel txtCorRealce;
    private javax.swing.JLabel txtCorTexto;
    private javax.swing.JLabel txtElementos;
    private javax.swing.JLabel txtLingua;
    // End of variables declaration//GEN-END:variables
}
